package com.bacon.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author： bacon、
 * @version： 1.0
 * @create： 2021-01-10 14:33
 * @description: 使用延迟插件，发送延续消息
 */
@Configuration
public class DelayMQConfig {

    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";


    //队列
    @Bean
    public Queue queueDelay() {
        return QueueBuilder.durable(queue_delay_1).build();
    }

    //交换机
    @Bean
    public Exchange exchangeDelay() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");

        //自定义交换机
        return new CustomExchange(
                exchange_delay,
                "x-delayed-message",
                true,
                false,
                map);
    }

    //绑定
    @Bean
    public Binding bindingDelay() {
        return BindingBuilder.
                bind(queueDelay()).
                to(exchangeDelay()).
                with(routing_delay).
                noargs();
    }
}
